<?php
require_once '../include/template_parser.php';

class AddEventView {
	function __construct() {}

	function display( $ano, $mes, $dia, $hora, $calendarios) {
		date_default_timezone_set('America/Santiago');
		$time = time();
		$year = ($ano == '') ? date('Y', $time) : $ano;
		$month = ($mes == '') ? date('n', $time) : $mes;
		$today = ($dia == '') ? date('j',$time) : $dia;

		$fecha = $today.'/'.$month.'/'.$year;

		$hora2 = $hora;

		$op_horas1 = '';
		$op_horas2 = '';
		for( $i = 0; $i < 24; $i++) {
			for( $j = 0; $j < 60; $j = $j + 15) {
				$h = ($i < 10) ? "0".$i : $i;
				$h .= ($j < 10) ? ":0".$j : ":".$j;

				if( $h == $hora) {
					$op_horas1 .= sprintf('<option value="%s" SELECTED >%s</option>', $h, $h);
					if( $i < 23) {
						$hora2 = (($i + 1) < 10) ? "0".($i + 1) : ($i + 1);
						$hora2 .= ($j < 10) ? ":0".$j : ":".$j;
					}
				} else {
					$op_horas1 .= sprintf('<option value="%s" >%s</option>', $h, $h);
				}

				if( $h == $hora2) {
					$op_horas2 .= sprintf('<option value="%s" SELECTED >%s</option>', $h, $h);
				} else {
					$op_horas2 .= sprintf('<option value="%s" >%s</option>', $h, $h);
				}
			}
		}

		$op_cal = '';
		if( $calendarios != NULL)
		foreach( $calendarios as $cal) {
			$op_cal .= sprintf( "<option value=\"%s\">%s</option>", $cal[0], $cal[1] );
		}

		$tags = array(
				'ano' => $year,
				'mes' => $month,
				'dia' => $today,
				
				'fecha_ini' => $fecha,
				'fecha_fin' => $fecha,
				'hora_ini' => $hora,
				'hora_fin' => $hora2,

				'option_calendarios' => $op_cal,

				'select_hora1' => $op_horas1,
				'select_hora2' => $op_horas2,

				'FUNC_CAL' => FUNC_CAL,
				'FCAL_ADD_EVENT' => FCAL_ADD_EVENT,
				'FCAL_LOAD_DIV_BY_TIME' => FCAL_LOAD_DIV_BY_TIME,
				'FADDE_ADD' => FADDE_ADD,
				'texto_down1' => 'VSN LCC &#169; 2012'
			);
		
		$template_parser = new TemplateParser( '../template/add_event_template.php', $tags);
		echo $template_parser->parse_template();
	}
}

?>
